﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.Core.Modelling.Primitives;

using System.Drawing;
using ITAP.Core.Modelling;

namespace ITAP.ContourBuilder.Components
{
    [Serializable]
    public class ContourHole : ContourComponent
    {
        public double Radius
        {
            get
            {
                return (Primitive.InnerPrimitives[0] as Circle).Radius;
            }
            set
            {
                ModelPoint startEndPoint = new ModelPoint(this.Position.X, this.Position.Y - value);
                Circle firstCircleHalf = new Circle(new ModelPoint(this.Position.X + value, this.Position.Y), new ModelPoint(this.Position.X - value, this.Position.Y), value);
                Circle secondCircleHalf = new Circle(new ModelPoint(this.Position.X - value, this.Position.Y), new ModelPoint(this.Position.X + value, this.Position.Y), value);
                List<IPrimitive> primitives = new List<IPrimitive>();
                primitives.Add(firstCircleHalf);
                primitives.Add(secondCircleHalf);

                this.Primitive = PrimitiveFactory.CreateCompositePrimitive(primitives);
            }
        }

        public override ModelPoint Position
        {
            get
            {
                return (this.Primitive.InnerPrimitives[0] as Circle).Center.Clone() as ModelPoint;
            }
        }

        public override System.Drawing.RectangleF BoundingBox
        {
            get
            {
                return this.Primitive.BoundingBox;
            }
        }

        public override void AcceptVisitor(IContourVisitor visitor)
        {
            visitor.Visit(this);
        }

        public override bool CanSelectByPoint(ModelPoint point)
        {
            PointF floatPoint = new PointF((float)point.X, (float)point.Y);
            if (this.BoundingBox.Contains(floatPoint))
                return true;
            else
                return false;
                    
        }

        public override void SelectByPoint(ModelPoint point)
        {
            if (this.CanSelectByPoint(point))
                this.selected = true;
        }

        public override bool IsComponentDotted
        {
            get
            {
                return false;
            }
        }
    }
}
